﻿using System.Linq;
using Basmus.Conel;

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;

namespace Basmus.Tests
{
    [TestClass()]
    public class ArrayBindingTest
    {


        private TestContext testContextInstance;

        
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        public void ArrayBindingConstructorTestHelper<TElement>()
        {
            var target = new ArrayBinding<TElement>();
            Assert.IsTrue(target.ElementType == typeof (TElement));

        }

        [TestMethod()]
        public void ArrayBindingConstructorTest()
        {
            var elemetTypes = TypeHelper.EveryPossibleElementTypes();
            this.InvokeMany("ArrayBindingConstructorTestHelper", elemetTypes);
        }

        

        public void GetElementsTestHelper<TElement>()
        {
            var target = new ArrayBinding<TElement>();
            var containersOfArray = ContainerHelper.GetContainersOfArray<TElement>();
            foreach (var conatiner in containersOfArray)
            {
                var expectedElements = conatiner;

                //Act
                var actualElements = target.GetElements(conatiner);

                //Assert
                CollectionAssertHelper.AreEqual(expectedElements, actualElements);
            }
        }

        [TestMethod()]
        public void GetElementsTest()
        {
            var elemetTypes = TypeHelper.EveryPossibleElementTypes();
            this.InvokeMany("GetElementsTestHelper", elemetTypes);
        }

        public void GetContainerTestHelper<TElement>()
        {
            //Arrange
            var target = new ArrayBinding<TElement>();
            var elementsCollection = ElementsHelper.GetElementsOf<TElement>();
            foreach (var elements in elementsCollection)
            {
                var elementsArg = elements == null ? null : elements.Cast<object>().ToArray();
                
                var expectedConatiner = elements;

                //Act
                var actualContainer = (TElement[])target.GetContainer(elementsArg);

                //Assert
                CollectionAssertHelper.AreEqual(expectedConatiner, actualContainer);
            }
        }

        [TestMethod()]
        public void GetContainerTest()
        {
            var elemetTypes = TypeHelper.EveryPossibleElementTypes();
            this.InvokeMany("GetContainerTestHelper", elemetTypes);
        }
    }
}
